package com.ttai.presenter.activity;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import android.widget.Toast;

import com.google.gson.JsonObject;
import com.ttai.model.dao.DBHelper;
import com.ttai.model.dao.bean.Acount_Item;
import com.ttai.model.net.ResponseInfo;
import com.ttai.presenter.base.BasePresenter;
import com.ttai.ui.activity.EnterPage;
import com.ttai.ui.activity.Register;
import com.ttai.ui.activity.UaP_Protect;
import com.ttai.untils.Constant;

import java.util.ArrayList;

import retrofit2.Call;

public class UapPresenter extends BasePresenter{
    UaP_Protect uaP_protect;
//    public static String phonenumber = "";
//    private ArrayList<Acount_Item> list = new ArrayList<>();
//    private ArrayList<String> nameList = new ArrayList<String>();

    public UapPresenter(UaP_Protect uaP_protect) {
        this.uaP_protect = uaP_protect;
    }

    @Override
    protected void showError(String message) {
        Toast.makeText(uaP_protect,message,Toast.LENGTH_SHORT).show();
    }

    @Override
    protected void parseJson(JsonObject json) {
//       DealDB();
        uaP_protect.getAdapter().notifyDataSetChanged();
        Toast.makeText(uaP_protect,"删除成功",Toast.LENGTH_SHORT).show();
        Log.i("789", "parseJson: "+uaP_protect.acountList.size());
        if (uaP_protect.acountList.size() == 0){
            uaP_protect.deleteTip();
        }







}

//    private void DealDB() {
//        DBHelper dbHelper = DBHelper.getInstance(uaP_protect);
//        SQLiteDatabase db=dbHelper.getWritableDatabase();
//        String appName = uaP_protect.getAppName();
//        db.delete("newacount", "acountname=?", new String[]{appName});
////        System.out.println("本地删除成功");
//        Cursor cursor=db.rawQuery("select acountname from newacount where phone = '" + phonenumber + "'",null);
//        while (cursor.moveToNext()){
//            String nameValue=cursor.getString(cursor.getColumnIndex("acountname"));
//            nameList.add(nameValue);
//        }
//        uaP_protect.getAdapter().notifyDataSetChanged();
//        cursor.close();
//        if (nameList.size()==0){
////            db.delete("tipacount","phone=?",new String[]{phonenumber});
//////            System.out.println("删除tipacount成功");
////        }
////        nameList.clear();

//    }

    public void acountDelete(String token,String acountName){
        Call<ResponseInfo> deleteInfo = responseInfoApi.acountdelete(token, acountName);
        deleteInfo.enqueue(new CallBackAdapter());
    }


//    public ArrayList<Acount_Item> getList(){
//        return list;
//    }

//    public void getData() {
//        if (HomePresrenter.myPhone==null || HomePresrenter.myPhone.isEmpty()){
//            if(Register.phonenumber==null || Register.phonenumber.isEmpty()){
//                phonenumber = EnterPage.enterphonenumber;
//            }else{
//                phonenumber =Register.phonenumber;
//            }
//        }else {
//            phonenumber = HomePresrenter.myPhone;
//        }
//        DBHelper dbHelper = DBHelper.getInstance(uaP_protect);
//        SQLiteDatabase db=dbHelper.getWritableDatabase();
//        Cursor cursor=db.rawQuery("select acountname,imgurl from newacount where phone = '" + phonenumber + "'",null);
//        while (cursor.moveToNext()){
//            String value=cursor.getString(cursor.getColumnIndex("acountname"));
//            String img = cursor.getString(cursor.getColumnIndex("imgurl"));
//            Acount_Item acount_item=new Acount_Item(value,img);
//            list.add(acount_item);
//        }
//        uaP_protect.getAdapter().setData(list);
//
//        cursor.close();
//            if (list.size()==0){
//                db.delete("tipacount","phone=?",new String[]{phonenumber});
////                System.out.println("删除tipacount成功");
//            }
//    }
}
